package com.qfan.mybatisflexdemo.config;

import com.mybatisflex.core.audit.AuditManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyBatisFlexConfiguration {

    private static final Logger logger = LoggerFactory.getLogger("mybatis-flex-sql");

    public MyBatisFlexConfiguration() {
        // 开启审计
        AuditManager.setAuditEnable(true);

        //设置 SQL 审计收集器
//        MessageCollector collector = new ConsoleMessageCollector();
//        AuditManager.setMessageCollector(collector);

        // 自定义sql审计收集器
        AuditManager.setMessageCollector(auditMessage -> {
            logger.info("执行sql耗时 {} ms >>>  {}", auditMessage.getElapsedTime(), auditMessage.getFullSql());
        });
    }
}
